package com.lins.framework.common.base;

import android.app.Application;
import android.content.Context;

import com.orhanobut.logger.AndroidLogAdapter;
import com.orhanobut.logger.FormatStrategy;
import com.orhanobut.logger.Logger;
import com.orhanobut.logger.PrettyFormatStrategy;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
 * Created by Admin on 2017/3/13.
 */

public class MyApplication extends Application {
    private static MyApplication instance;
    private static Context context;
    private static String OK_HTTP_TAG = "OKLOG";
    private ActivityManager activityManager = null; // activity管理类
    private Executor excutor = null; // 线程池执行器


    public static MyApplication getInstance() {
        return instance;
    }

    @Override
    public void onCreate() {
        activityManager = ActivityManager.getInstance(); // 获得实例
        excutor = Executors.newFixedThreadPool(5); // 拥有固定数量5的线程池
        super.onCreate();
        instance = this;
        MyApplication.context = getApplicationContext();
//        //设备的物理高度进行百分比化
//        AutoLayoutConifg.getInstance().useDeviceSize();

        initLog();
    }

    public ActivityManager getActivityManager() {
        return activityManager;
    }

    public Executor getExcutor() {
        return excutor;
    }

    private void initLog() {
        FormatStrategy formatStrategy = PrettyFormatStrategy.newBuilder()
                .showThreadInfo(false)  // (Optional) Whether to show thread info or not. Default true
                .methodCount(0)         // (Optional) How many method line to show. Default 2
                .methodOffset(7)        // (Optional) Hides internal method calls up to offset. Default 5
//                .logStrategy(customLog) // (Optional) Changes the log strategy to print out. Default LogCat
                .tag(OK_HTTP_TAG)   // (Optional) Global tag for every log. Default PRETTY_LOGGER
                .build();
        Logger.addLogAdapter(new AndroidLogAdapter(formatStrategy) {
            @Override
            public boolean isLoggable(int priority, String tag) {
                //true：打开LOG，false：关闭LOG
                return true;
            }
        });
    }

    public void onLowMemory() {
        super.onLowMemory();
        System.gc();
    }

}
